package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-09-30
 * Time:11:33
 */
public class DelOperation implements IOperation{
    @Override
    public void ioperation(BookList bookList) {
        System.out.println("删除图书");
        //查找是否有
        System.out.println("请输入需要删除的图书：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        for (int i = 0; i < bookList.getUseSize(); i++) {
            Book book=bookList.getPos(i);
            if(name.equals(book.getName())){
                System.out.println("找到这本书了");
                for (int j = i; j < bookList.getUseSize(); j++) {
                    bookList.setBooks(bookList.getPos(j+1),j);
                }
                bookList.setUseSize(bookList.getUseSize()-1);
                System.out.println("已经删除图书了");
                break;
            }
            if(i== bookList.getUseSize()-1){
                System.out.println("没有这本书");
            }
        }

    }
}
